﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SettingPanel : BasePanel<SettingPanel>
{
    public CustomGUIToggle tgMusic;
    public CustomGUIToggle tgAudio;
    public CustomGUISlider musicVolume;
    public CustomGUISlider audioVolume;
    public CustomGUIButton btnClose;

    void Start()
    {
        Hide();
        tgMusic.changeValue += (bool select) =>
        {
            GameDataMgr.Instance.OpenOrCloseMusic(select);
            BackMusic.Instance.ChangeEnable(select);
        };
        tgAudio.changeValue += (bool select) =>
        {
            GameDataMgr.Instance.OpenOrCloseAudio(select);
        };
        musicVolume.changeValue += (float value) =>
        {
            GameDataMgr.Instance.ChangeMusicVolume(value);
            BackMusic.Instance.ChangeVolume(value);
        };
        audioVolume.changeValue += (float value) => GameDataMgr.Instance.ChangeAudioVolume(value);
        btnClose.clickEvent += () =>
        {
            Hide();
            //判断当前场景
            if (SceneManager.GetActiveScene().name == "Start")
            {
                StartPanel.Instance.Show();
            }
        };
    }

    public void UpdatePanelInfo()
    {
        MusicData data = GameDataMgr.Instance.musicData;
        //设置面板内容
        tgMusic.isSel = data.music;
        tgAudio.isSel = data.audio;
        musicVolume.nowValue = data.musicVolume;
        audioVolume.nowValue = data.audioVolume;
    }

    public override void Show()
    {
        base.Show();
        UpdatePanelInfo();
    }
}
